package com.mm.dss.demo;

import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.mm.dss.demo.base.BaseActivity;
import com.mm.dss.demo.bean.YhdBean;
import com.mm.dss.demo.bean.YhdMsgBean;
import com.mm.dss.demo.tools.Constances;
import com.mm.dss.demo.tools.WebServiceUtils;
import com.mm.dss.demo.tools.WeiboDialogUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.ksoap2.serialization.SoapObject;

import java.util.HashMap;
import java.util.Map;

public class XxcxInfoActivity  extends BaseActivity {
    TextView txt_yj;
    TextView txt_title;
    RelativeLayout layout_back;
    TextView time;
    TextView citySubdivision;
    TextView location;
    private Dialog mWeiboDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xxcx_info);
        txt_title= (TextView) findViewById(R.id.txt_title);
        txt_yj= (TextView) findViewById(R.id.txt_yj);
        citySubdivision= (TextView) findViewById(R.id.citySubdivision);
        location= (TextView) findViewById(R.id.location);
        layout_back= (RelativeLayout) findViewById(R.id.layout_back);
        time= (TextView) findViewById(R.id.time);
        txt_title.setText(getIntent().getStringExtra("title"));
        layout_back.setVisibility(View.VISIBLE);
//        txt_yj.setText(getIntent().getStringExtra("txt"));
//        time.setText(getIntent().getStringExtra("time"));
        setnet();
    }
    public void onclick(View view){
        switch (view.getId())
        {

            case R.id.layout_back:
                finish();
                break;
        }
    }

    private void setnet() {
        mWeiboDialog = WeiboDialogUtils.
                createLoadingDialog(XxcxInfoActivity.this,
                        "加载中...");
        Map<String,String> map=new HashMap<>();
        map.put("ID",getIntent().getStringExtra("ID"));
        WebServiceUtils.callWebService(Constances.webhosturl, "N10_GetYHDDetail", map, new WebServiceUtils.WebServiceCallBack() {
            @Override
            public void callBack(SoapObject result) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                try {
                    JSONArray array=new JSONArray(result.getProperty(0).toString());
                    Gson gson=new Gson();
                    YhdMsgBean yhdMsgBean=gson.fromJson(array.optJSONObject(0).toString(),YhdMsgBean.class);
                    txt_yj.setText(yhdMsgBean.getLX());
                    citySubdivision.setText("城区："+yhdMsgBean.getWENTI());
                    location.setText("地点："+yhdMsgBean.getWEIZHI());
                    time.setText("时间："+yhdMsgBean.getTIME());
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }
}
